Popular Searches
Popular Course Categories
Popular Courses

Extent Reports

Screenshots & Reporting

Extent Reports

Extent Reports is a reporting framework used with automated testing tools such as Selenium WebDriver and TestNG to generate detailed, interactive, and visually rich test execution reports. It helps QA engineers and developers understand which tests passed, failed, or were skipped and provides additional execution information such as logs, screenshots, categories, authors, devices, and test steps.

In modern Java automation frameworks, ExtentReports 5 uses ExtentSparkReporter for HTML reporting. Older classes such as ExtentHtmlReporter and ExtentLoggerReporter were removed in ExtentReports 5, with Spark being the replacement for HTML-style reporting. :contentReference[oaicite:0]{index=0}

ExtentReports follows a logger-style API. A test can be created with createTest(), execution details can be recorded with methods such as pass(), fail(), info(), and warning(), and the final information is written to the configured reporter using flush(). :contentReference[oaicite:1]{index=1}

Course Resource: Selenium Training | Register for Course Demo


1. What are Extent Reports?

Extent Reports are detailed test execution reports generated by the ExtentReports reporting framework. They provide a structured view of automated test results and can include test names, execution status, logs, screenshots, metadata, categories, authors, devices, exceptions, and other execution information.

In a Selenium automation framework, Extent Reports can be used to convert raw test execution activity into a readable report that can be shared with developers, QA teams, managers, and other stakeholders.

A simplified reporting flow is:

TestNG Test

     |

     v

Selenium WebDriver

     |

     v

Test Execution

     |

     v

ExtentReports

     |

     v

ExtentSparkReporter

     |

     v

HTML Report


2. Why are Extent Reports Important?

Automated test execution can generate a large amount of information. Console output alone is often not sufficient for understanding the complete execution history. Extent Reports organize this information into a structured and interactive report.

  • Shows passed, failed, skipped, and other test statuses.
  • Provides detailed execution logs.
  • Helps identify failed test cases.
  • Can include screenshots.
  • Supports test categories and tags.
  • Supports authors and device information.
  • Provides an interactive HTML report through Spark.
  • Helps with debugging failed Selenium tests.
  • Can be integrated into TestNG automation frameworks.
  • Can be used in CI/CD automation workflows.
  • Provides a central view of test execution information.


3. Extent Reports Architecture

ExtentReports separates the report-building API from the destination that renders or stores the information. The main ExtentReports object manages the test session, while a reporter such as ExtentSparkReporter receives the information and produces the report.

Test Automation Framework

          |

          v

      TestNG Tests

          |

          v

     ExtentReports

          |

          v

   ExtentSparkReporter

          |

          v

      Spark HTML

          |

          v

   Interactive Report

ExtentReports uses a reporter-based design in which one or more reporters can receive the test information. The official Java documentation describes reporters as destinations for information generated during a test session. :contentReference[oaicite:2]{index=2}


4. Main Components of Extent Reports

ComponentPurpose
ExtentReportsMain report client that manages the reporting session.
ExtentSparkReporterGenerates the Spark HTML report.
ExtentTestRepresents an individual test and allows logs, nodes, attributes, and screenshots.
StatusRepresents execution states such as PASS, FAIL, SKIP, WARNING, and INFO.
createTest()Creates a test entry in the report.
createNode()Creates a child node or test step hierarchy.
flush()Writes accumulated report information to the configured reporter.
MediaEntityBuilderHelps attach screenshots or other media to test logs.


5. ExtentReports Class

The ExtentReports class is the main reporting client used to create tests and connect reporters. In a typical test session, one ExtentReports instance is maintained for the reporting lifecycle.

ExtentReports extent = new ExtentReports();

The official documentation recommends maintaining a single ExtentReports instance for a test session, and the library provides thread-safe methods for its reporting operations. :contentReference[oaicite:3]{index=3}


6. ExtentSparkReporter

ExtentSparkReporter is the primary HTML reporter used with ExtentReports 5. It generates the interactive Spark report file.

ExtentSparkReporter spark =

        new ExtentSparkReporter("test-output/ExtentReport.html");

The reporter can then be attached to the ExtentReports instance.

ExtentReports extent = new ExtentReports();

 

ExtentSparkReporter spark =

        new ExtentSparkReporter("test-output/ExtentReport.html");

 

extent.attachReporter(spark);

ExtentReports 5 replaced older HTML reporter classes with ExtentSparkReporter. :contentReference[oaicite:4]{index=4}


7. Maven Dependency

For a Maven-based Java project, ExtentReports can be added as a dependency. Maven Central currently lists version 5.1.2 for the com.aventstack:extentreports artifact. :contentReference[oaicite:5]{index=5}

<dependency>

    <groupId>com.aventstack</groupId>

    <artifactId>extentreports</artifactId>

    <version>5.1.2</version>

</dependency>

In a real project, the dependency version should be managed according to the project's Java version, framework compatibility, dependency policy, and currently approved library versions.


8. Creating a Basic Extent Report

The basic process consists of creating the report object, creating a Spark reporter, attaching it, creating a test, logging the result, and flushing the report.

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

 

public class ExtentBasicExample {

 

    public static void main(String[] args) {

 

        ExtentSparkReporter spark =

                new ExtentSparkReporter("test-output/ExtentReport.html");

 

        ExtentReports extent = new ExtentReports();

        extent.attachReporter(spark);

 

        ExtentTest test =

                extent.createTest("Login Test");

 

        test.pass("Login test executed successfully");

 

        extent.flush();

    }

}

The official documentation demonstrates the same basic lifecycle: create ExtentReports, attach ExtentSparkReporter, create a test, log an event, and call flush. :contentReference[oaicite:6]{index=6}


9. Understanding createTest()

The createTest() method creates a test entry and returns an ExtentTest object. The returned object can then be used to add logs and other test information.

ExtentTest test = extent.createTest("Login Test");

 

test.pass("Login successful");

A description can also be supplied:

ExtentTest test = extent.createTest(

        "Login Test",

        "Validate successful user login"

);

The ExtentReports API supports both test-name-only and test-name-with-description forms of createTest. :contentReference[oaicite:7]{index=7}


10. ExtentTest

ExtentTest represents an individual test or node in the report. It can be used to log execution information and create hierarchical child nodes.

ExtentTest test = extent.createTest("Search Test");

 

test.info("Opening application");

test.info("Entering search keyword");

test.pass("Search completed successfully");

ExtentTest can also be used to assign attributes such as categories, devices, and authors and to attach screenshots. :contentReference[oaicite:8]{index=8}


11. Logging Test Information

Logs describe what happened during the execution of a test. ExtentReports provides several status-oriented methods.

test.info("Opening browser");

test.info("Navigating to login page");

test.pass("Login successful");

test.warning("Page load time was higher than expected");

test.fail("Login validation failed");

test.skip("Test skipped because prerequisite failed");

Common statuses include:

StatusTypical Use
INFOGeneral execution information.
PASSSuccessful validation or step.
FAILFailed validation or execution.
WARNINGUnexpected condition that does not necessarily fail the test.
SKIPTest or step was skipped.


12. Using Status Enum

Instead of convenience methods, logs can be created using the Status enumeration.

import com.aventstack.extentreports.Status;

 

test.log(Status.INFO, "Opening application");

test.log(Status.PASS, "Login successful");

test.log(Status.WARNING, "Slow response detected");

test.log(Status.FAIL, "Expected element was not displayed");

test.log(Status.SKIP, "Test skipped");


13. The Importance of flush()

The flush() method writes the collected test information to the configured reporters. Calling flush is an essential part of the reporting lifecycle.

extent.flush();

The official documentation specifically states that flush is required to ensure information is written to the started reporters. :contentReference[oaicite:9]{index=9}

A simplified lifecycle is:

Create ExtentReports

        |

        v

Attach Reporter

        |

        v

Create Tests

        |

        v

Add Logs

        |

        v

Attach Screenshots

        |

        v

Flush

        |

        v

HTML Report Generated


14. Selenium Integration with Extent Reports

ExtentReports becomes particularly useful when integrated with Selenium WebDriver. Selenium performs browser automation while ExtentReports records the execution information.

WebDriver driver = new ChromeDriver();

 

ExtentTest test = extent.createTest("Google Search");

 

test.info("Opening Google");

 

driver.get("https://www.google.com");

 

test.pass("Google opened successfully");

 

driver.quit();


15. Complete Selenium and Extent Reports Example

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class SeleniumExtentExample {

 

    public static void main(String[] args) {

 

        ExtentSparkReporter spark =

                new ExtentSparkReporter("test-output/ExtentReport.html");

 

        ExtentReports extent = new ExtentReports();

        extent.attachReporter(spark);

 

        ExtentTest test =

                extent.createTest("Google Test");

 

        WebDriver driver = new ChromeDriver();

 

        try {

            test.info("Opening Google");

 

            driver.get("https://www.google.com");

 

            test.pass("Google opened successfully");

 

        } catch (Exception e) {

 

            test.fail(e);

 

        } finally {

 

            driver.quit();

            extent.flush();

        }

    }

}


16. Extent Reports with TestNG

ExtentReports is commonly integrated with TestNG in Selenium frameworks. TestNG controls test execution while ExtentReports records the results.

TestNG

   |

   +-- @BeforeMethod

   |

   +-- @Test

   |

   +-- @AfterMethod

   |

   v

ExtentReports

   |

   v

Spark HTML Report


17. TestNG Listener Integration

For a scalable framework, TestNG listeners can be used to automatically update ExtentReports when tests start, pass, fail, or skip.

The ITestListener interface provides lifecycle callbacks that can be connected to the reporting layer.

public class TestListener implements ITestListener {

 

    @Override

    public void onTestStart(ITestResult result) {

        // Create ExtentTest

    }

 

    @Override

    public void onTestSuccess(ITestResult result) {

        // Log PASS

    }

 

    @Override

    public void onTestFailure(ITestResult result) {

        // Log FAIL

    }

 

    @Override

    public void onTestSkipped(ITestResult result) {

        // Log SKIP

    }

}


18. Creating a Report Manager

A separate report manager can centralize ExtentReports initialization. This avoids creating the reporting object repeatedly in every test class.

public class ExtentManager {

 

    private static ExtentReports extent;

 

    public static ExtentReports getInstance() {

 

        if (extent == null) {

 

            ExtentSparkReporter spark =

                    new ExtentSparkReporter(

                        "test-output/ExtentReport.html"

                    );

 

            extent = new ExtentReports();

            extent.attachReporter(spark);

        }

 

        return extent;

    }

}


19. Creating ExtentTest from a Listener

A listener can create an ExtentTest whenever a TestNG test starts.

public class TestListener implements ITestListener {

 

    private static ExtentReports extent =

            ExtentManager.getInstance();

 

    private static ThreadLocal<ExtentTest> test =

            new ThreadLocal<>();

 

    @Override

    public void onTestStart(ITestResult result) {

 

        ExtentTest extentTest =

                extent.createTest(

                    result.getMethod().getMethodName()

                );

 

        test.set(extentTest);

    }

}

ThreadLocal is commonly used in parallel test frameworks to associate a test object with the current execution thread.


20. Logging Test Success

@Override

public void onTestSuccess(ITestResult result) {

 

    test.get().pass(

        "Test Passed: " +

        result.getMethod().getMethodName()

    );

}


21. Logging Test Failure

When a TestNG test fails, the listener can record the exception in ExtentReports.

@Override

public void onTestFailure(ITestResult result) {

 

    test.get().fail(result.getThrowable());

}

Recording the exception makes the report more useful for debugging because the failure information appears with the corresponding test.


22. Logging Skipped Tests

@Override

public void onTestSkipped(ITestResult result) {

 

    test.get().skip(

        "Test skipped: " +

        result.getMethod().getMethodName()

    );

}


23. Flushing the Report from Listener

The report should be flushed after the test execution lifecycle has completed.

@Override

public void onFinish(ITestContext context) {

    ExtentManager.getInstance().flush();

}


24. Complete TestNG Listener Example

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import org.testng.ITestContext;

import org.testng.ITestListener;

import org.testng.ITestResult;

 

public class TestListener implements ITestListener {

 

    private static ExtentReports extent =

            ExtentManager.getInstance();

 

    private static ThreadLocal<ExtentTest> test =

            new ThreadLocal<>();

 

    @Override

    public void onTestStart(ITestResult result) {

 

        ExtentTest extentTest =

                extent.createTest(

                    result.getMethod().getMethodName()

                );

 

        test.set(extentTest);

    }

 

    @Override

    public void onTestSuccess(ITestResult result) {

 

        test.get().pass("Test Passed");

    }

 

    @Override

    public void onTestFailure(ITestResult result) {

 

        test.get().fail(result.getThrowable());

    }

 

    @Override

    public void onTestSkipped(ITestResult result) {

 

        test.get().skip("Test Skipped");

    }

 

    @Override

    public void onFinish(ITestContext context) {

 

        extent.flush();

    }

}


25. Registering TestNG Listener

A TestNG listener can be registered using the @Listeners annotation.

import org.testng.annotations.Listeners;

 

@Listeners(TestListener.class)

public class LoginTest {

 

    // Test methods

}

Another approach is registering the listener through a TestNG XML suite.

<listeners>

    <listener class-name="listeners.TestListener"/>

</listeners>


26. Adding Test Description

A test description provides additional context about what the test validates.

ExtentTest test = extent.createTest(

        "Login Test",

        "Validate successful login using valid credentials"

);


27. Creating Test Nodes

ExtentReports supports hierarchical test information through createNode(). A node can represent a logical step or subsection within a test.

ExtentTest test =

        extent.createTest("Login Test");

 

ExtentTest node =

        test.createNode("Enter Credentials");

 

node.info("Entering username");

node.info("Entering password");

node.pass("Credentials entered successfully");

The official documentation describes createNode as a way to create child sections within a test hierarchy. :contentReference[oaicite:10]{index=10}


28. Test Step Reporting

Nodes can make a Selenium report easier to understand by separating major test steps.

ExtentTest test =

        extent.createTest("Login Test");

 

ExtentTest loginStep =

        test.createNode("Login Steps");

 

loginStep.info("Open login page");

loginStep.info("Enter username");

loginStep.info("Enter password");

loginStep.info("Click login button");

loginStep.pass("Login completed");


29. Adding Categories

Categories can be used to group tests logically, for example Smoke, Regression, Sanity, Login, Checkout, or Search.

ExtentTest test =

        extent.createTest("Login Test");

 

test.assignCategory("Smoke");

test.assignCategory("Login");

Categories make it easier to organize and filter report information.


30. Assigning Authors

Authors can identify the person or automation owner associated with a test.

ExtentTest test =

        extent.createTest("Login Test");

 

test.assignAuthor("Automation Team");

In larger teams, author metadata can help identify ownership of tests.


31. Assigning Devices

Device information can be attached to a test execution.

ExtentTest test =

        extent.createTest("Login Test");

 

test.assignDevice("Chrome - Windows");

For cross-browser testing, device metadata can make the generated report easier to analyze.


32. Adding Multiple Attributes

ExtentTest test =

        extent.createTest("Checkout Test");

 

test.assignCategory("Regression");

test.assignCategory("Checkout");

test.assignAuthor("QA Team");

test.assignDevice("Chrome");


33. Adding Screenshots

Screenshots are extremely useful when investigating Selenium failures. ExtentReports supports screenshot attachments through media entities.

test.fail(

    MediaEntityBuilder

        .createScreenCaptureFromPath(

            "screenshots/failure.png"

        )

        .build()

);

The ExtentReports documentation includes screenshot attachment support through MediaEntityBuilder. :contentReference[oaicite:11]{index=11}


34. Screenshot on Failure

A common Selenium framework design is to automatically capture a screenshot when a test fails.

public void captureFailure(

        WebDriver driver,

        ExtentTest test) {

 

    String path =

        ScreenshotUtil.captureScreenshot(driver);

 

    test.fail(

        "Test failed",

        MediaEntityBuilder

            .createScreenCaptureFromPath(path)

            .build()

    );

}


35. Selenium Screenshot Utility

public class ScreenshotUtil {

 

    public static String captureScreenshot(

            WebDriver driver) {

 

        TakesScreenshot ts =

                (TakesScreenshot) driver;

 

        File source =

                ts.getScreenshotAs(OutputType.FILE);

 

        String path =

                "test-output/screenshots/"

                + System.currentTimeMillis()

                + ".png";

 

        File destination =

                new File(path);

 

        try {

            FileUtils.copyFile(

                source,

                destination

            );

        } catch (IOException e) {

            throw new RuntimeException(e);

        }

 

        return path;

    }

}


36. Screenshot with TestNG Listener

The listener can capture a screenshot automatically when a test fails.

@Override

public void onTestFailure(ITestResult result) {

 

    WebDriver driver =

        DriverManager.getDriver();

 

    String screenshot =

        ScreenshotUtil.captureScreenshot(driver);

 

    test.get().fail(

        result.getThrowable(),

        MediaEntityBuilder

            .createScreenCaptureFromPath(

                screenshot

            )

            .build()

    );

}


37. Handling Exceptions in Reports

Exceptions should be recorded with the test that generated them.

try {

 

    driver.findElement(

        By.id("loginButton")

    ).click();

 

} catch (Exception e) {

 

    test.fail(e);

}

This allows the report to contain the exception information instead of only a generic failure message.


38. Logging Selenium Actions

test.info("Opening application");

 

driver.get("https://example.com");

 

test.info("Entering username");

 

driver.findElement(

    By.id("username")

).sendKeys("admin");

 

test.info("Entering password");

 

driver.findElement(

    By.id("password")

).sendKeys("password");

 

test.info("Clicking Login");

 

driver.findElement(

    By.id("loginButton")

).click();

 

test.pass("Login workflow completed");


39. Extent Reports with Assertions

Assertions validate expected application behavior. ExtentReports can document the result of those validations.

String actualTitle =

        driver.getTitle();

 

String expectedTitle =

        "Dashboard";

 

Assert.assertEquals(

    actualTitle,

    expectedTitle

);

 

test.pass("Dashboard title validated");

When using a listener-based design, assertion failures can be captured automatically from the TestNG result.


40. Parameterized Test Reporting

ExtentReports can be used with TestNG Data Providers so that multiple test-data combinations are visible in the reporting system.

@DataProvider(name = "users")

public Object[][] users() {

    return new Object[][] {

        {"admin", "admin123"},

        {"manager", "manager123"},

        {"employee", "employee123"}

    };

}

 

@Test(dataProvider = "users)

public void loginTest(

        String username,

        String password) {

 

    // Login test

}

Each TestNG invocation can be associated with its own reporting information. For production frameworks, the reporting listener should ensure that the test instance is correctly associated with the current invocation.


41. Reporting Test Parameters

Test data can be added to logs, but sensitive values such as passwords should not be exposed.

test.info("Username: " + username);

test.info("Password: [MASKED]");

Logging sensitive credentials into reports can create unnecessary security risks, especially when reports are stored in shared CI/CD locations.


42. Extent Reports and Page Object Model

ExtentReports can be integrated with Page Object Model architecture. Page classes handle Selenium interactions while tests and listeners handle reporting.

Test Class

    |

    +-- ExtentTest

    |

    v

Page Object

    |

    v

Selenium WebDriver

    |

    v

Application

This separation helps prevent reporting logic from being scattered throughout every page class.


43. POM and Extent Reports Example

public class LoginPage {

 

    private WebDriver driver;

 

    private By username =

        By.id("username");

 

    private By password =

        By.id("password");

 

    private By loginButton =

        By.id("loginButton");

 

    public LoginPage(WebDriver driver) {

        this.driver = driver;

    }

 

    public void login(

            String user,

            String pass) {

 

        driver.findElement(username)

                .sendKeys(user);

 

        driver.findElement(password)

                .sendKeys(pass);

 

        driver.findElement(loginButton)

                .click();

    }

}

The test can report the business-level actions while the page class remains focused on application interaction.


44. Extent Reports Configuration

ExtentSparkReporter can be configured for the generated report. Common configuration areas include report title, document title, theme, encoding, and view configuration.

ExtentSparkReporter spark =

        new ExtentSparkReporter(

            "test-output/ExtentReport.html"

        );

 

spark.config().setDocumentTitle(

        "Automation Test Report"

);

 

spark.config().setReportName(

        "Selenium Regression Test Report"

);

The exact available configuration methods can vary by library version, so framework code should be aligned with the version used by the project.


45. Report Name and Document Title

A clear report name helps identify the purpose of the report.

spark.config().setDocumentTitle(

        "Selenium Automation Report"

);

 

spark.config().setReportName(

        "Regression Test Execution"

);


46. Adding System Information

System information can be added to an ExtentReports session to provide execution context.

extent.setSystemInfo(

    "Operating System",

    System.getProperty("os.name")

);

 

extent.setSystemInfo(

    "Java Version",

    System.getProperty("java.version")

);

 

extent.setSystemInfo(

    "User",

    System.getProperty("user.name")

);

Additional values can include environment, browser, build number, application version, or execution type.


47. Environment Information

extent.setSystemInfo(

    "Environment",

    "QA"

);

 

extent.setSystemInfo(

    "Browser",

    "Chrome"

);

 

extent.setSystemInfo(

    "Application",

    "E-Commerce Portal"

);


48. Browser Information

Browser information is particularly useful in Selenium cross-browser testing.

extent.setSystemInfo(

    "Browser",

    "Chrome"

);

 

extent.setSystemInfo(

    "Browser Version",

    "Current"

);

For dynamically determined browser versions, the framework can obtain the value from WebDriver capabilities or its driver-management layer.


49. Report Filtering

ExtentReports supports reporter filtering so that different report outputs can be produced from the same test information. The official documentation provides examples of using multiple Spark reporters with different status filters. :contentReference[oaicite:12]{index=12}

For example, a framework can conceptually produce:

Complete Report

       |

       +-- All Tests

       |

       +-- Failed Tests

       |

       +-- Passed Tests


50. Multiple Reporters

One ExtentReports instance can be connected to multiple reporters. This can be useful when the same execution information needs to be published to different destinations.

ExtentReports extent =

        new ExtentReports();

 

ExtentSparkReporter spark =

        new ExtentSparkReporter(

            "test-output/Spark.html"

        );

 

extent.attachReporter(spark);

ExtentReports supports attaching multiple reporters to the same reporting client. :contentReference[oaicite:13]{index=13}


51. Extent Reports and Parallel Execution

Parallel Selenium execution requires careful management of WebDriver and test objects. Each concurrent execution should be isolated so that logs and screenshots are associated with the correct test.

Thread 1

   |

   +-- WebDriver 1

   +-- ExtentTest 1

 

Thread 2

   |

   +-- WebDriver 2

   +-- ExtentTest 2

 

Thread 3

   |

   +-- WebDriver 3

   +-- ExtentTest 3

ThreadLocal is commonly used for per-thread ExtentTest references in parallel TestNG frameworks.


52. ThreadLocal with ExtentTest

private static ThreadLocal<ExtentTest> test =

        new ThreadLocal<>();

 

public static ExtentTest getTest() {

    return test.get();

}

 

public static void setTest(

        ExtentTest extentTest) {

    test.set(extentTest);

}

The objective is to prevent concurrent test executions from accidentally writing logs into another test's report entry.


53. Extent Reports and CI/CD

Extent Reports can be generated as part of a CI/CD pipeline. After automated tests finish, the generated report can be stored as a build artifact or published through the CI system.

Developer Commit

       |

       v

CI/CD Pipeline

       |

       v

Build

       |

       v

TestNG

       |

       v

Selenium Tests

       |

       v

ExtentReports

       |

       v

Spark HTML

       |

       v

Build Artifact


54. Extent Reports with Jenkins

A typical Jenkins workflow can execute Maven tests and then archive the generated Extent report.

mvn clean test

The framework may generate:

test-output/

    |

    +-- ExtentReport.html

    |

    +-- screenshots/

    |      |

    |      +-- failure-001.png

    |      +-- failure-002.png

    |

    +-- logs/

The CI configuration can then publish or archive these files according to the project's reporting requirements.


55. Extent Reports and Maven

ExtentReports integrates naturally with Maven-based Selenium projects.

mvn clean test

The typical flow is:

Maven

  |

  v

TestNG

  |

  v

Selenium

  |

  v

ExtentReports

  |

  v

test-output/ExtentReport.html


56. Report Directory Structure

A clean automation framework can maintain report-related files in a dedicated output directory.

test-output

|

|-- ExtentReport.html

|

|-- screenshots

|   |-- login-failure.png

|   |-- checkout-failure.png

|

|-- logs

|   |-- execution.log


57. Extent Reports and Screenshots Directory

When screenshots are stored as separate files, use a predictable directory structure.

test-output/

    screenshots/

        LoginTest_failure.png

        SearchTest_failure.png

        CheckoutTest_failure.png

File naming should make it possible to identify the associated test without exposing sensitive test data.


58. Extent Reports for Failed Tests

A useful failure report should ideally contain:

  • Test name.
  • Failure status.
  • Exception information.
  • Relevant test step logs.
  • Screenshot when appropriate.
  • Browser information.
  • Environment information.
  • Execution timestamp.


59. Extent Reports for Passed Tests

Passed tests should also contain enough information to demonstrate what was successfully validated.

Test: Login Test

 

INFO  - Open application

INFO  - Enter username

INFO  - Enter password

INFO  - Click login

PASS  - Dashboard displayed


60. Extent Reports for Skipped Tests

Skipped tests should have a meaningful reason where possible.

test.skip(

    "Skipped because prerequisite test failed"

);

Useful skip reasons help distinguish intentionally skipped tests from unexpected execution problems.


61. Extent Reports and Regression Testing

Extent Reports are particularly useful for regression suites because a large number of tests may run during a single execution.

Regression Suite

      |

      +-- Login

      +-- Search

      +-- Product

      +-- Cart

      +-- Checkout

      +-- Payment

      +-- Profile

      |

      v

Extent Report

The report provides a centralized view of the execution results.


62. Extent Reports and Smoke Testing

Smoke tests can be tagged as a category.

ExtentTest test =

        extent.createTest("Login Smoke Test");

 

test.assignCategory("Smoke");

 

test.pass("Smoke test passed");

This allows smoke-related tests to be distinguished from larger regression suites.


63. Extent Reports and Test Categories

CategoryExample
SmokeBasic application availability tests.
RegressionExisting functionality validation.
SanityFocused validation after changes.
LoginAuthentication-related tests.
CheckoutE-commerce checkout tests.
APIAPI-related automation tests.


64. Extent Reports and BDD

ExtentReports supports Gherkin-style structures. A BDD hierarchy can represent Feature, Scenario, Given, When, Then, and related nodes. :contentReference[oaicite:14]{index=14}

Feature

   |

   +-- Scenario

         |

         +-- Given

         +-- When

         +-- Then

This hierarchy can be created through the BDD APIs provided by ExtentReports.


65. Extent Reports and JSON Archives

ExtentReports 5 provides a JSON representation that can be used to rebuild and combine reporting information from multiple build sessions. The official documentation describes JsonFormatter and createDomainFromJsonArchive() for this purpose. :contentReference[oaicite:15]{index=15}

Previous Execution

       |

       v

extent.json

       |

       v

Current Execution

       |

       v

Combined Reporting Data

       |

       v

Spark Report


66. Extent Reports and Custom Markup

ExtentReports supports markup content for richer report information. This can be useful for formatted code, structured information, or custom report details.

test.info(

    MarkupHelper.createCodeBlock(

        "System.out.println(\"Hello\");"

    )

);

The official documentation includes MarkupHelper examples for creating code blocks and other markup content. :contentReference[oaicite:16]{index=16}


67. Logging Custom Information

test.info(

    "Application Version: 2.5.0"

);

 

test.info(

    "Environment: QA"

);

 

test.info(

    "Browser: Chrome"

);

Custom information should be useful for diagnosing the execution while avoiding unnecessary sensitive or personal data.


68. Extent Reports and Dashboard Information

The Spark report provides multiple views for analyzing test execution information. The ExtentReports documentation describes views such as Test, Category, Device, Author, Exception, Dashboard, and Log. :contentReference[oaicite:17]{index=17}

Extent Spark Report

       |

       +-- Dashboard

       +-- Test

       +-- Category

       +-- Author

       +-- Device

       +-- Exception

       +-- Log


69. Extent Reports and Exception Analysis

Exception information is particularly useful for Selenium failures such as element-not-found errors, timeout exceptions, stale element errors, and assertion failures.

Test Failure

     |

     v

Exception

     |

     +-- Message

     +-- Stack Trace

     +-- Screenshot

     +-- Test Steps

     |

     v

Extent Report


70. Complete Extent Reports TestNG Example

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import com.aventstack.extentreports.MediaEntityBuilder;

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

 

public class LoginTest {

 

    private WebDriver driver;

 

    private static ExtentReports extent;

    private ExtentTest test;

 

    @BeforeMethod

    public void setup() {

 

        if (extent == null) {

 

            ExtentSparkReporter spark =

                new ExtentSparkReporter(

                    "test-output/ExtentReport.html"

                );

 

            extent = new ExtentReports();

            extent.attachReporter(spark);

        }

 

        test = extent.createTest(

            "Login Test",

            "Validate login functionality"

        );

 

        driver = new ChromeDriver();

 

        test.info("Browser launched");

    }

 

    @Test

    public void loginTest() {

 

        try {

 

            test.info("Opening application");

 

            driver.get(

                "https://example.com/login"

            );

 

            test.info("Application opened");

 

            // Login steps would be implemented here.

 

            Assert.assertTrue(

                driver.getTitle().length() > 0

            );

 

            test.pass(

                "Login test validation completed"

            );

 

        } catch (Exception e) {

 

            test.fail(

                e

            );

 

            Assert.fail(e.getMessage());

        }

    }

 

    @AfterMethod

    public void tearDown() {

 

        if (driver != null) {

            driver.quit();

        }

 

        if (extent != null) {

            extent.flush();

        }

    }

}


71. Recommended Listener-Based Architecture

For a larger Selenium TestNG framework, reporting logic is usually better centralized in a listener rather than manually creating and flushing reports inside every test class.

                 Selenium Framework

                        |

          +-------------+-------------+

          |             |             |

          v             v             v

       Tests         POM         Utilities

          |             |             |

          +-------------+-------------+

                        |

                        v

                 TestNG Listener

                        |

                        v

                  ExtentReports

                        |

                        v

               ExtentSparkReporter

                        |

                        v

                  HTML Report


72. Practical Project Structure

src

|

|-- test

|   |

|   +-- java

|       |

|       +-- tests

|       |   |-- LoginTest.java

|       |   |-- SearchTest.java

|       |   |-- CheckoutTest.java

|       |

|       +-- pages

|       |   |-- LoginPage.java

|       |   |-- SearchPage.java

|       |   |-- CheckoutPage.java

|       |

|       +-- listeners

|       |   |-- TestListener.java

|       |

|       +-- reports

|       |   |-- ExtentManager.java

|       |

|       +-- utilities

|           |-- DriverFactory.java

|           |-- ScreenshotUtil.java

|

|-- test-output

    |-- ExtentReport.html

    |-- screenshots


73. Recommended Framework Responsibilities

ComponentResponsibility
Test ClassDefines business-level test scenarios.
Page ClassHandles Selenium page interactions.
Driver FactoryCreates and manages WebDriver instances.
Test ListenerHandles TestNG lifecycle events.
Extent ManagerCreates and manages ExtentReports.
Screenshot UtilityCaptures Selenium screenshots.
ExtentSparkReporterGenerates the Spark HTML report.


74. Common Mistakes in Extent Reports

  • Forgetting to call extent.flush().
  • Creating multiple report instances unnecessarily.
  • Using obsolete ExtentReports APIs from older versions.
  • Using ExtentHtmlReporter when working with ExtentReports 5.
  • Not attaching ExtentSparkReporter.
  • Not capturing failure information.
  • Saving screenshots to invalid paths.
  • Using the same ExtentTest object across parallel tests.
  • Logging passwords or tokens into reports.
  • Generating unclear test names.
  • Adding excessive logs that make reports difficult to read.
  • Failing to clean old report artifacts in CI environments.


75. ExtentReports 4 vs ExtentReports 5

FeatureOlder VersionsVersion 5
HTML ReporterExtentHtmlReporterExtentSparkReporter
Logger ReporterAvailable in older versionsRemoved
Spark ReporterNot the primary older APIPrimary HTML reporting option
createTest()SupportedSupported
createNode()SupportedSupported
flush()RequiredRequired

ExtentReports documentation confirms that ExtentHtmlReporter and ExtentLoggerReporter were removed in version 5 and ExtentSparkReporter is their replacement for the modern reporting workflow. :contentReference[oaicite:18]{index=18}


76. Extent Reports vs TestNG Reports

FeatureTestNG ReportExtent Reports
Test ResultsYesYes
Interactive HTML ReportingBasicRich and interactive
Custom LogsLimitedExtensive
ScreenshotsRequires custom handlingSupported through media attachments
CategoriesLimitedSupported
AuthorsLimitedSupported
DevicesLimitedSupported
CustomizationLimitedExtensive


77. Extent Reports vs Console Logs

Console LogsExtent Reports
Mostly text-basedInteractive report
Harder to navigate after large executionStructured test information
Limited screenshot supportScreenshot attachments
Limited metadataCategories, authors, devices, and other metadata
Not designed as a formal test reportDesigned for test reporting


78. Best Practices for Extent Reports

  • Use a centralized ExtentReports manager.
  • Use ExtentSparkReporter for ExtentReports 5.
  • Use TestNG listeners for centralized lifecycle handling.
  • Use meaningful test names.
  • Log important business-level steps rather than every minor implementation detail.
  • Capture screenshots on important failures.
  • Attach exception information to failed tests.
  • Use categories for Smoke, Regression, Sanity, and feature groups.
  • Use author and device information when useful.
  • Use ThreadLocal for per-thread ExtentTest objects in parallel execution.
  • Never expose passwords, tokens, or other secrets in reports.
  • Keep screenshot and report directories organized.
  • Call flush at the correct lifecycle point.
  • Keep reporting logic separate from page-object implementation logic.
  • Archive reports in CI/CD according to project requirements.


79. Real-World Selenium Reporting Flow

TestNG Suite

     |

     v

Test Listener

     |

     +-------------------+

     |                   |

     v                   v

ExtentTest          WebDriver

     |                   |

     v                   v

Test Logs           Selenium Actions

     |                   |

     +---------+---------+

               |

               v

        Pass / Fail / Skip

               |

               v

          Screenshot

               |

               v

      ExtentSparkReporter

               |

               v

         HTML Report


80. Real-World E-Commerce Example

Consider an e-commerce application with Login, Search, Product Details, Cart, and Checkout modules. Extent Reports can organize the execution results for all these areas.

E-Commerce Regression

        |

        +-- Login Test

        |     +-- Open Login

        |     +-- Enter Credentials

        |     +-- Submit

        |     +-- Verify Dashboard

        |

        +-- Search Test

        |     +-- Enter Product

        |     +-- Search

        |     +-- Verify Results

        |

        +-- Cart Test

        |     +-- Add Product

        |     +-- Open Cart

        |     +-- Verify Product

        |

        +-- Checkout Test

              +-- Enter Address

              +-- Select Payment

              +-- Place Order

              +-- Verify Confirmation


81. Practical Failure Reporting Example

Test: Checkout Test

Status: FAIL

 

Steps:

1. Open checkout page

2. Enter shipping address

3. Select payment method

4. Click Place Order

 

Failure:

Element not found

 

Screenshot:

checkout-failure.png

 

Environment:

QA

 

Browser:

Chrome

This type of report gives the QA engineer enough context to begin investigating the failed test.


82. Security Considerations

Reports can contain application URLs, usernames, screenshots, error messages, request information, and other execution details. Therefore, reporting should be designed with security in mind.

  • Do not log passwords.
  • Mask authentication tokens.
  • Avoid exposing API keys.
  • Review screenshots for sensitive information.
  • Restrict access to reports when necessary.
  • Avoid logging personal information unless required for testing.
  • Clean sensitive temporary artifacts after execution.


83. Reporting Checklist

Checklist ItemStatus to Verify
ExtentReports dependency addedRequired
ExtentSparkReporter configuredRequired
Reporter attachedRequired
Tests createdRequired
Logs addedRecommended
Failure exceptions capturedRecommended
Screenshots capturedRecommended
Categories assignedOptional
Author/device informationOptional
System informationRecommended
flush() executedRequired


84. Interview Questions on Extent Reports

1. What is ExtentReports?

ExtentReports is a reporting library used to generate detailed and interactive reports for automated test execution.

2. Which reporter is commonly used with ExtentReports 5?

ExtentSparkReporter is the primary HTML reporter in ExtentReports 5.

3. What is ExtentReports?

ExtentReports is the main reporting client used to manage the test reporting session and attach reporters.

4. What is ExtentTest?

ExtentTest represents a test or node and is used to add logs, statuses, attributes, and media.

5. What does createTest() do?

It creates a test entry and returns an ExtentTest object.

6. What does createNode() do?

It creates a child node within a test to represent a subsection or test step hierarchy.

7. Why is flush() important?

flush() writes the collected reporting information to the configured reporter.

8. Can ExtentReports capture screenshots?

Yes. Screenshots can be attached through ExtentReports media APIs such as MediaEntityBuilder.

9. Can ExtentReports work with Selenium?

Yes. It is commonly integrated with Selenium WebDriver automation frameworks.

10. Can ExtentReports work with TestNG?

Yes. TestNG listeners are commonly used to connect test lifecycle events to ExtentReports.

11. What is a TestNG listener?

A listener receives TestNG execution lifecycle events such as test start, success, failure, and skip.

12. Why use ThreadLocal with ExtentTest?

ThreadLocal can associate an ExtentTest object with the current execution thread during parallel testing.

13. Can categories be assigned to tests?

Yes. Tests can be assigned categories such as Smoke, Regression, Login, and Checkout.

14. Can authors be assigned?

Yes. Author information can be assigned to ExtentTest objects.

15. Can device information be assigned?

Yes. Device or browser information can be associated with a test.

16. Can multiple reporters be attached?

Yes. ExtentReports supports attaching multiple reporters to the same reporting client.

17. What replaced ExtentHtmlReporter in ExtentReports 5?

ExtentSparkReporter is the modern replacement for ExtentHtmlReporter in version 5.

18. How can failed screenshots be added?

A Selenium screenshot can be captured and attached to the failed ExtentTest using MediaEntityBuilder.

19. How can ExtentReports be integrated with Jenkins?

The report can be generated during the CI build and stored or published as a build artifact according to the Jenkins configuration.

20. What is the main benefit of ExtentReports?

It provides structured, detailed, and interactive test execution information that makes automated test results easier to analyze and share.


85. Quick Reference Table

ConceptPurpose
ExtentReportsMain reporting client.
ExtentSparkReporterGenerates Spark HTML report.
ExtentTestRepresents a test or reporting node.
createTest()Creates a test.
createNode()Creates a child test node.
pass()Logs successful execution.
fail()Logs failed execution.
info()Logs general information.
warning()Logs a warning.
skip()Logs a skipped test.
assignCategory()Assigns test category.
assignAuthor()Assigns test author.
assignDevice()Assigns device/browser information.
MediaEntityBuilderCreates media attachments such as screenshots.
flush()Writes report data to the reporter.
ITestListenerConnects TestNG lifecycle events to reporting.
ThreadLocalHelps isolate test references during parallel execution.


86. Learning Roadmap for Extent Reports

  1. Understand TestNG reporting basics.
  2. Understand the purpose of ExtentReports.
  3. Learn the ExtentReports and ExtentTest classes.
  4. Learn ExtentSparkReporter.
  5. Add ExtentReports to a Maven project.
  6. Create a basic report.
  7. Learn createTest().
  8. Learn logging methods such as pass(), fail(), info(), and skip().
  9. Understand flush().
  10. Integrate ExtentReports with Selenium.
  11. Integrate ExtentReports with TestNG.
  12. Learn ITestListener.
  13. Build a centralized ExtentManager.
  14. Capture Selenium screenshots.
  15. Add screenshots to failed tests.
  16. Add categories, authors, and device information.
  17. Add environment and system information.
  18. Integrate ExtentReports with Page Object Model.
  19. Handle parallel execution with ThreadLocal.
  20. Integrate reports into Maven and CI/CD.
  21. Build a complete reusable Selenium reporting framework.


87. Practical Exercises

  1. Create a basic ExtentSparkReporter HTML report.
  2. Create a Selenium test and log each major test step.
  3. Create PASS and FAIL test scenarios.
  4. Attach a screenshot to a failed test.
  5. Create a TestNG ITestListener.
  6. Automatically create an ExtentTest when a TestNG test starts.
  7. Automatically mark tests as PASS, FAIL, and SKIP.
  8. Create an ExtentManager class.
  9. Add browser and environment information.
  10. Add Smoke and Regression categories.
  11. Assign author and device information.
  12. Integrate ExtentReports with Page Object Model.
  13. Use ThreadLocal for parallel test execution.
  14. Generate the report through Maven.
  15. Publish the report as part of a CI/CD pipeline.


88. Real-World Extent Reports Architecture

                 Selenium Test Framework

                           |

          +----------------+----------------+

          |                |                |

          v                v                v

       TestNG             POM          Data Provider

          |                |                |

          +----------------+----------------+

                           |

                           v

                    TestNG Listener

                           |

                           v

                     ExtentTest

                           |

             +-------------+-------------+

             |             |             |

             v             v             v

           Logs       Screenshots    Metadata

             |             |             |

             +-------------+-------------+

                           |

                           v

                    ExtentReports

                           |

                           v

                 ExtentSparkReporter

                           |

                           v

                    Spark HTML Report

                           |

                           v

                       CI/CD


89. Summary

Extent Reports is a powerful reporting solution for Selenium and TestNG automation frameworks. It provides a structured and interactive way to understand automated test execution.

The basic reporting architecture consists of ExtentReports, ExtentSparkReporter, and ExtentTest. Tests are created using createTest(), execution information is recorded using logging methods, screenshots can be attached when required, and flush() writes the collected information to the configured reporter.

For a professional Selenium framework, ExtentReports can be combined with TestNG listeners, Page Object Model, Data Providers, screenshot utilities, driver factories, parallel execution, Maven, and CI/CD pipelines.

The most important practical objective is not simply generating an HTML file, but creating a report that clearly explains what was tested, what happened, where it failed, why it failed, and what evidence is available for investigation.


90. Course Resources

Learn more about Selenium automation and professional testing concepts:

Final Takeaway: Extent Reports transforms Selenium and TestNG execution data into detailed, readable, and interactive reports. By combining ExtentSparkReporter, ExtentTest, TestNG listeners, screenshots, logs, categories, metadata, and centralized reporting utilities, automation teams can build a maintainable reporting layer suitable for local execution, regression testing, and CI/CD workflows.

whatsapp